package com.file.system.plugin.shiro;

import com.file.system.plugin.websocket.PublicTask;
import com.file.system.plugin.websocket.WebSocketServer;
import org.apache.shiro.session.Session;
import org.apache.shiro.session.SessionListener;

import static com.file.system.entity.res.BaseCode.Common.USER_TIME_OUT;


public class ShiroSessionListener implements SessionListener {

    /**
     * 会话创建时触发
     *
     * @param session
     */
    @Override
    public void onStart(Session session) {

    }

    /**
     * 退出会话时触发
     *
     * @param session
     */
    @Override
    public void onStop(Session session) {
        //提示用户超时
        WebSocketServer.sendMessage(USER_TIME_OUT, USER_TIME_OUT.getMessage(), session.getId().toString());
    }

    /**
     * 会话过期时触发
     *
     * @param session
     */
    @Override
    public void onExpiration(Session session) {
        //提示用户超时
        WebSocketServer.sendMessage(USER_TIME_OUT, USER_TIME_OUT.getMessage(), session.getId().toString());
    }

}
